package com.zzl.rabbitmq.hello;

import com.rabbitmq.client.*;

/**
 * Title: Consumer.class<br>
 * Description: <br>
 * Copyright (c)  2021    <br>
 * Create DateTime: 2021/7/1 11:31 <br>
 *
 * @author zhuangzhuangliang
 */
public class Consumer {
    public static final String QUEUE_NAME = "hello";

    public static void main(String[] args)  throws Exception{
        ConnectionFactory factory = new ConnectionFactory();
        factory.setHost("192.168.211.132");
        factory.setUsername("zzl");
        factory.setPassword("zzl");
        //获取连接
        Connection connection = factory.newConnection();
        //获取channel
        Channel channel = connection.createChannel();

        DeliverCallback deliverCallback = (consumerTag, message) ->{
            String msg = new String(message.getBody());
            System.out.println(msg);
        };

        CancelCallback cancelCallback = consumerTag ->{
            System.out.println("消息中断");
        };

        channel.basicConsume(QUEUE_NAME,deliverCallback,cancelCallback);
    }
}
